<?php
/**
 * Aero - Xistins Technologies PHP Framework
 * 
 * LICENSE
 * This source file is subject to the New BSD license that is bundled 
 * with this package in the LICENSE.txt. It is also available through 
 * the world-wide-web at this URL: http://dev.xistins.com/license/production
 * If you did not receive a copy of this license and are unable to obtain
 * it through the world-wide-web, please send an email to 
 * license@xistins.com so we can send you a copy immediately.
 * 
 * @category   Aero
 * @package    Aero_Db
 * @subpackage Statement
 * @copyright  http://dev.xistins.com/license/production     New BSD
 * @version    $Id: Pdo.php 2 2009-11-03 04:10:03Z csouth@xistins.com $
 */

require_once 'Aero/Db/Statement.php';

/**
 * Abstract database adapter
 * 
 * @category   Aero
 * @package    Aero_Db
 * @subpackage Statement
 * @copyright  http://dev.xistins.com/license/production     New BSD
 * @version    $Id: Pdo.php 2 2009-11-03 04:10:03Z csouth@xistins.com $
 */
class Aero_Db_Statement_Pdo extends Aero_Db_Statement
{
    /**
     * Execute Query
     * 
     * @return bool
     */
    protected function _execute()
    {
        try {
            $this->_stmt = $this->getAdapter()->getConnection()->prepare($this->_query);
            return $this->_stmt->execute();
        } catch(PDOException $e) {
            Aero_Loader::loadClass('Aero_Db_Exception');
            throw new Aero_Db_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }

    /**
     * Fetch first result
     * 
     * @return StdClass
     */
    protected function _fetch()
    {
        try {
            return $this->_stmt->fetchObject();
        } catch (PDOException $e) {
            Aero_Loader::loadClass('Aero_Db_Exception');
            throw new Aero_Db_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }

    /**
     * Fetch all results
     * 
     * @return StdClass
     */
    protected function _fetchAll()
    {
        try {
            return $this->_stmt->fetchAll(PDO::FETCH_OBJ);
        } catch (PDOException $e) {
            Aero_Loader::loadClass('Aero_Db_Exception');
            throw new Aero_Db_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }
}